package com.onlinefurnitureshop.management.controller;

import java.util.List;

import com.onlinefurnitureshop.management.model.Resource;
import com.onlinefurnitureshop.management.service.ResourceService;

public class ResourceAction {
	private ResourceService resourceService;
	private List<Resource> resourceList;
	private List<Resource> menuList;
	private Resource resource;
	private Long id;
	private Long pid;
	
	
	
	
	

	public Long getPid() {
		return pid;
	}

	public void setPid(Long pid) {
		this.pid = pid;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

	public List<Resource> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<Resource> menuList) {
		this.menuList = menuList;
	}

	public List<Resource> getResourceList() {
		return resourceList;
	}

	public void setResourceList(List<Resource> resourceList) {
		this.resourceList = resourceList;
	}

	public ResourceService getResourceService() {
		return resourceService;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}
	
	
	public String list(){
		resourceList = resourceService.findAll();
		for(Resource resource:resourceList){
			System.out.println(resource.getParentIds()+resource.getId());
		}
		return "resourceList";
	}
	
	
	public String showCreateForm(){
		id=null;
		resource = new Resource();
		menuList = resourceService.findAllMenus();
		return "resourceEdit";
	}
	
	public  String create(){
		resourceService.createResource(resource);
		return "listAction";
	}
	
	public String showUpdateForm(){
		System.out.println("resource"+id);
		resource = resourceService.findOne(id);
		menuList = resourceService.findAllMenus();
		return "resourceEdit";
	}
	
	public String update(){
		resourceService.updateResource(resource);
		return "listAction";
	}
	
	public String showDeleteForm(){
		return "resourceDelete";
	}
	
	public String delete(){
		System.out.println("Resource Delete:"+id);
		resourceService.deleteResource(id);
		return "listAction";
	}


}
